package com.classloader;

import java.sql.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YJ
 * Date: 2023-11-05
 * Time: 20:05
 */
public class JDBCExample {
    static final String JDBC_DROVER = "com.mysql.cj.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql:///demo1";
    static final String USER = "root";
    static final String PASS = "123456";

    public static void main(String[] args) {
        Connection coon = null;
        Statement stmt = null;
        try {
            coon = DriverManager.getConnection(DB_URL,USER,PASS);
            stmt = coon.createStatement();
            String sql = "select name,author from book";
            ResultSet r = stmt.executeQuery(sql);
            while (r.next()) {
                System.out.print("name: " + r.getString("name"));
                System.out.print("author: " + r.getString("author") + "\n");
            }
            stmt.close();
            coon.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
